package network.盗版qq.qqclient.view;

import network.盗版qq.qqclient.service.SendMessageService;
import network.盗版qq.qqclient.service.UserClientService;

import java.util.Scanner;

/**
 * @author mubei
 * @date 2021/12/6
 * @description
 */
public class QQView {

    // 控制是否显示菜单
    private boolean loop = true;

    private int key;

    // 用于登录服务  注册用户的
    private UserClientService userClientService = new UserClientService();

    // 消息传送的服务
    private SendMessageService sendMessageService = new SendMessageService();
    // 显示主菜单

    public void mainMenu() {
        while (loop) {
            System.out.println("======欢迎登录网络通信系统======");
            System.out.println("\t\t1.登录系统");
            System.out.println("\t\t9.退出系统");
            System.out.println("请输入你的选择");
            Scanner scanner = new Scanner(System.in);
            key = scanner.nextInt();


            switch (key) {
                case 1:
                    System.out.print("输入用户号:");
                    String userId = scanner.next();
                    System.out.print("请输入密码:");
                    String password = scanner.next();
                   /*
                   * 需要去 服务端验证是否合法
                   * 编写一个服务类
                   * 检测用户名密码是否正确
                   * */
                    if ( userClientService.checkUser(userId, password)) {// 先把逻辑打通
                        System.out.println("======欢迎(用户" + userId + "登录成功)======");
                        // 二级菜单
                        while (loop) {
                            System.out.println("\n======网络通信系统二级菜单(用户" + userId + ")======");
                            System.out.println("\t\t1.在线用户列表");
                            System.out.println("\t\t2.群发消息");
                            System.out.println("\t\t3.私聊消息");
                            System.out.println("\t\t4.发送文件");
                            System.out.println("\t\t9.退出系统");
                            System.out.print("请输入选择:");
                            key = scanner.nextInt();
                            switch (key) {
                                case 1:
                                    // 写一个方法在这里返回用户列表
                                    userClientService.onLineFriendList();
                                    break;
                                case 2:
                                    System.out.println("\t\t2.群发消息");
                                    System.out.print("输入想对大家说的话");
                                    String content1 = scanner.next();
                                    sendMessageService.sendMessageToAll(content1,userId);
                                    break;
                                case 3:
                                    System.out.print("请输入想聊天的用户好(在线):");
                                    String getterId = scanner.next();
                                    System.out.print("输入想说的话");
                                    String content = scanner.next();
                                    sendMessageService.sendMessageToOne(content,userId,getterId);
                                    break;
                                case 4:
                                    System.out.println("\t\t4.发送文件");
                                    break;
                                case 9:
                                    userClientService.clientExit();
                                    loop = false;
                            }
                        }

                    } else {
                        System.out.println("======登录失败======");
                    }
                    break;
                case 9:
                    loop = false;
                    break;
            }
        }
    }

    public static void main(String[] args) {
        QQView qqView = new QQView();
        qqView.mainMenu();
        System.out.println("客户端退出系统.....");
    }
}
